<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>GT pro钱包</title>
		<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
		<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
		<link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
		<link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
		<link rel="stylesheet" href="bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
		<link rel="stylesheet" href="dist/css/AdminLTE.min.css">
		<link rel="stylesheet" href="dist/css/skins/skin-blue.min.css">
		<link rel="stylesheet" href="css/style.css">
		<link rel="stylesheet" href="css/card.css">
		<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
		<link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css">
		<link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">

		<style>
			.table img {
				width: 75px;
				height: 75px;
			}
			
			input.picInput {
				display: none;
			}
			
			img.picShow {
				width: 80px;
				height: 80px;
			}
			.fr_swich .fr_swich_txt{
				width:100px;
			}
		</style>
	</head>

	<body class="hold-transition skin-blue sidebar-mini">
		<div class="wrapper">
			<div class="content-wrapper">
				<section class="content-header">
					<ol class="breadcrumb">
						<li>
							<a href="#"><i class="fa fa-dashboard"></i>系统设置</a>
						</li>
						<li class="">主链列表</li>
						<li class="active">币种列表</li>
					</ol>
				</section>
				<section class="content">
					<div class="box">
						<div class="box-header with-border">
							币种列表
						</div>
						<div class="box-body">
							<div class="buyu_search_group">
								<div class="row" style="margin-bottom:10px;">
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<!-- <button type="button" class="btn bg-primary margin" onclick="add()"><i class="fa fa-plus" ></i>&nbsp;新增</button> -->
									</div>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-xs-12">
								<!-- /.box-header -->
								<div class="box-body">
									<table id="example" class="display nowrap table table-bordered table-striped" style="width:100%;">
										<thead>
											<tr>
												<th>id</th>
												<th>名称</th>
												<th>主链id</th>
												<th>logo</th>
												<th>添加时间</th>
												<th>操作</th>
											</tr>
										</thead>
										<tbody></tbody>
									</table>
								</div>
							</div>
						</div>
					</div>

				</section>
			</div>
		</div>
		<div class="modal fade parents in" id="passwordModal" style="z-index:1051;">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">	                  							
							<span aria-hidden="true">×</span>								
						</button>
						<h4 class="modal-title">密码确认</h4>
					</div>
					<div class="modal-body">
						<form class="form-horizontal">
							<input type="password" class="form-control" name="OPassword" placeholder="请输入操作密码">
						</form>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary save" onclick="editSave()">确定</button>
					</div>
				</div>
			</div>
		</div>
		<div class="modal fade parents in" id="addPasswordModal" style="z-index:1051;">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">	                  							
							<span aria-hidden="true">×</span>								
						</button>
						<h4 class="modal-title">密码确认</h4>
					</div>
					<div class="modal-body">
						<form class="form-horizontal">
							<input type="password" class="form-control" name="OPassword" placeholder="请输入操作密码">
						</form>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary save" onclick="addSave()">确定</button>
					</div>
				</div>
			</div>
		</div>
		<div class="modal fade parents in" id="editCoinModal">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header"> 
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">	            
							<span aria-hidden="true">×</span>				
						</button>
						<h4 class="modal-title">币种编辑</h4> 
					</div>
					<div class="modal-body">
						<div class="row">
							<input type="hidden" name="id" value="">
							<label class="margin-bottom-none col-xs-12">名称
								<input type="text" class="form-control" name="name" >
							</label>
							<div class="margin-bottom-none col-xs-12">
								<div>logo</div>
								<label style="display: inline-block;">
									<input type="file" class="form-control onePic picInput" name="edit_img"/>
									<img src="img/add.png" class="picShow" alt="" name="edit_img"/>
								</label>
							</div>
							<div class="col-xs-12" style="line-height: 2;">是否主币:
								<div class="col-xs-12" style="padding: 0;">
									<label class="margin-r-5" style="font-weight: normal;">
										<input type="radio" name="is_main" value="1" style="margin:0 5px 0 0;">是
									</label>
									<label class="margin-r-5" style="font-weight: normal;">
										<input type="radio" name="is_main" value="0" style="margin:0 5px 0 0;">否
									</label>
								</div>
							</div>
							<div class="col-xs-12" style="line-height: 2;">是否默认资产:
								<div class="col-xs-12" style="padding: 0;">
									<label class="margin-r-5" style="font-weight: normal;">
										<input type="radio" name="is_default" value="1" style="margin:0 5px 0 0;">是
									</label>
									<label class="margin-r-5" style="font-weight: normal;">
										<input type="radio" name="is_default" value="0" style="margin:0 5px 0 0;">否
									</label>
								</div>
							</div>
							<label class="margin-bottom-none col-xs-12">热地址保留余额
								<input type="text" class="form-control" name="hot_max_coin" >
							</label>
							<label class="margin-bottom-none col-xs-12">合约地址
								<input type="text" class="form-control" name="agreement_address" >
							</label>
							<label class="margin-bottom-none col-xs-12">用户最多余额
								<input type="text" class="form-control" name="max_balance">
							</label>
							
							<label class="margin-bottom-none col-xs-12">需审核数量
								<input type="text" class="form-control" name="verify_num">
							</label>
							<label class="margin-bottom-none col-xs-12">示警数量<span class="text-red">(币低于指定值时提醒)</span>
								<input type="text" class="form-control" name="warn_balance">
							</label>
							<!-- <div class="form-group col-xs-12">
								<label class="control-label" style="font-weight:normal;">价格来源</label>
								<select name="price_from" class="form-control">
									<option value="1">非小号</option>
									<option value="2">aofex</option>
									<option value="3">atop</option>
									<option value="4">火币网</option>
								</select>
							</div> -->
							<!-- <div class="form-group col-xs-12">
								<label class="control-label" style="font-weight:normal;">是否可充值游戏</label>
								<select name="recharge_status" class="form-control">
									<option value="1">可充值</option>
									<option value="0">不可充值</option>
								</select>
							</div> -->
							<label class="margin-bottom-none col-xs-12">手续费</span>
								<div class="input-group">
									<input type="text" class="form-control" name="charge_number">
									<div class="input-group-addon">
										<div class="">
											<select class="coin_id" name="charge_coin_id"></select>
										</div>
									</div>
								</div>
							</label>
							<label class="margin-bottom-none col-xs-12">默认usdt价格
								<input type="text" class="form-control" name="default_usd_price">
							</label>
							<label class="margin-bottom-none col-xs-12">默认人民币价格
								<input type="text" class="form-control" name="default_cny_price">
							</label>
							
							<label class="margin-bottom-none col-xs-12">热地址
								<input type="text" class="form-control" name="hot_address">
							</label>
							<label class="margin-bottom-none col-xs-12">热地址私钥
								<input type="text" class="form-control" name="hot_address_private_key">
							</label>
							<label class="margin-bottom-none col-xs-12">冷地址
								<input type="text" class="form-control" name="cold_address">
							</label>
							<label class="margin-bottom-none col-xs-12"><span style="display:inline-block;">trc20的币种</span>
								<input class="open" type="checkbox" style="margin-top: 9px;" name="is_trc20" >
							</label>
							
							<!-- <label class="margin-bottom-none col-xs-12"><span style="display:inline-block;">实名制</span>
								<div>
									<div class="fr_swich  active" id="need_auth">
										<div class="fr_swich_body"></div>
										<span class="fr_swich_txt">需要</span>
									</div>
								</div>
								
							</label> -->
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary save" onclick="editNext()">确定</button>
					</div>
				</div>
			</div>
		</div>
		<!-- <div class="modal fade parents in" id="addCoinModal">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header"> 
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">	            
							<span aria-hidden="true">×</span>				
						</button>
						<h4 class="modal-title">新增币种</h4> 
					</div>
					<div class="modal-body">
						<div class="row">
							<input type="hidden" name="id" value="">
							<label class="margin-bottom-none col-xs-12">名称
								<input type="text" class="form-control" name="name" >
							</label>
							<div class="margin-bottom-none col-xs-12">
								<div>logo</div>
								<label style="display: inline-block;">
									<input type="file" class="form-control onePic picInput" name="edit_img"/>
									<img src="img/add.png" class="picShow" alt="" name="edit_img"/>
								</label>
							</div>
							<div class="col-xs-12" style="line-height: 2;">是否主币:
								<div class="col-xs-12" style="padding: 0;">
									<label class="margin-r-5" style="font-weight: normal;">
										<input type="radio" name="add_is_main" value="1" style="margin:0 5px 0 0;">是
									</label>
									<label class="margin-r-5" style="font-weight: normal;">
										<input type="radio" name="add_is_main" value="0" style="margin:0 5px 0 0;">否
									</label>
								</div>
							</div>
							<div class="col-xs-12" style="line-height: 2;">是否默认资产:
								<div class="col-xs-12" style="padding: 0;">
									<label class="margin-r-5" style="font-weight: normal;">
										<input type="radio" name="add_is_default" value="1" style="margin:0 5px 0 0;">是
									</label>
									<label class="margin-r-5" style="font-weight: normal;">
										<input type="radio" name="add_is_default" value="0" style="margin:0 5px 0 0;">否
									</label>
								</div>
							</div>
							<label class="margin-bottom-none col-xs-12">热地址保留余额
								<input type="text" class="form-control" name="hot_max_coin" >
							</label>
							<label class="margin-bottom-none col-xs-12">合约地址
								<input type="text" class="form-control" name="agreement_address" >
							</label>
							<label class="margin-bottom-none col-xs-12">用户最多余额
								<input type="text" class="form-control" name="max_balance">
							</label>
							<label class="margin-bottom-none col-xs-12">示警数量<span class="text-red">(币低于指定值时提醒)</span>
								<input type="text" class="form-control" name="warn_balance">
							</label>
							
							<label class="margin-bottom-none col-xs-12">手续费</span>
								<div class="input-group">
									<input type="text" class="form-control" name="charge_number">
									<div class="input-group-addon">
										<div class="">
											<select class="coin_id" name="charge_coin_id" id=""></select>
										</div>
									</div>
								</div>
								
								
							</label>
							<label class="margin-bottom-none col-xs-12">默认usdt价格
								<input type="text" class="form-control" name="default_usd_price">
							</label>
							<label class="margin-bottom-none col-xs-12">默认人民币价格
								<input type="text" class="form-control" name="default_cny_price">
							</label>
							
							<label class="margin-bottom-none col-xs-12">热地址
								<input type="text" class="form-control" name="hot_address">
							</label>
							<label class="margin-bottom-none col-xs-12">热地址私钥
								<input type="text" class="form-control" name="hot_address_private_key">
							</label>
							<label class="margin-bottom-none col-xs-12">冷地址
								<input type="text" class="form-control" name="cold_address">
							</label>
							<label class="margin-bottom-none col-xs-12"><span style="display:inline-block;">trc20的币种</span>
								<input class="open" type="checkbox" style="margin-top: 9px;" name="is_trc20" >
							</label>
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary save" onclick="addNext()">确定</button>
					</div>
				</div>
			</div>
		</div> -->
		<script src="bower_components/jquery/dist/jquery.min.js"></script>
		<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
		<script src="bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
		<script src="bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>

		<script src="bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
		<script src="bower_components/moment/min/moment.min.js"></script>
		<script src="bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>

		<script src="dist/js/adminlte.min.js"></script>
		<script type="text/javascript" src="./libs/spark-md5-3.0.0.min.js"></script>
		<script type="text/javascript" src="./libs/crypto-js.js"></script>
		<script type="text/javascript" src="./libs/base64.min.js"></script>
		<script type="text/javascript" src="./libs/ufile-token.js"></script>
		<script src="js/argument.js"></script>
		<script src="js/fun.js"></script>
		<script src="js/nav.js"></script>
		<script src="js/pop.js"></script>
		<script type="text/javascript">
			$("[code = 300]").addClass('menu-open').find("ul.treeview-menu").show();
			$("[pageid = 304]").parent().addClass('active');
			var init = true
			var table = $('#example').DataTable({
				'ordering': false,
				'lengthChange': false,
				'searching': false,
				'info': true,
				"processing": true,
				"serverSide": true,
				'scrollX':true,
				"ajax": {
					"type": 'post',
					"url": url + "Back_MainChainForCoin",
					'contentType': "application/x-www-form-urlencoded",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					"data": function(d) {
						var Json = {} //renderData(dataType);
						Json.page_num = d.start / 10 + 1;
						Json.chain_id = GetRequest().chain_id;
						var data = {};
						data.data = JSON.stringify(Json);
						return data;
					},
					"dataFilter": function(data) {
						var datajson = eval('(' + data + ')');
						if(datajson.status == 1000||datajson.status == 102) {
							ToLogin(datajson)
							return false;
						} else if(datajson.status != 1) {
							alert(datajson.error);
							return false;
						}
						var json = {};
						if(datajson.data == null) {
							json.recordsTotal = 0;
							json.recordsFiltered = 0;
							json.data = [];
							return JSON.stringify(json);
						} else {
							if(init){
								$.each(datajson.data,function(index,item){
									$(".coin_id").append("<option value='"+item.id+"'>"+item.name+"</option>")
								})
								init = false
							}
							
							json.recordsTotal = datajson.data.length;
							json.recordsFiltered = datajson.data.length;
							json.data = datajson.data;
							return JSON.stringify(json);
						}
					}
				},
				"columns": [{
						data: 'id'
					},
					{
						data: 'name'
					},
					{
						data: 'chain_id'
					},
					{
						data: null,
						render: function(data) {
							if(data.logo.indexOf("http") != -1) {
								return '<img src = "' + data.logo + '">';
							} else {
								return '<img src = "' + bucketUrl + data.logo + '">';
							}

						}
					},
					{
						data: 'add_time'
					},
					{
						data: null,
						render: function(data) {
							return "<input type='hidden' value='" + JSON.stringify(data) + "'><button type='button' class='btn btn-primary button-margin' onclick='editCoin(this)'><i class='fa fa-pencil'></i>&nbsp;编辑</button>"
						}
					}
				]
			})
		</script>
		<script type="text/javascript">
			
			
			var ufile = new UCloudUFile(bucketName, bucketUrl, tokenPublicKey, tokenPrivateKey, tokenServerUrl, prefix);




			function editCoin(_this) {
				var data = JSON.parse($(_this).siblings('input').val())
				console.log(data);
				$("#editCoinModal").modal('show');
				$.each(data, function(index, item) {
					console.log(index);
					if(index == 'is_main' || index == 'is_default') {
						$("#editCoinModal [name=" + index + "][value = " + item + "]").prop('checked', true);
						return;
					}else if(index ==  "hot_address_private_key"){
						$("#editCoinModal [name= hot_address_private_key]").attr('oldValue',item);
					}else if(index ==  "is_trc20"){
						item ? $("#editCoinModal [name= is_trc20]").prop('checked',true):$("#editCoinModal [name= is_trc20]").prop('checked',false)
					}
					$("#editCoinModal [name=" + index + "]").val(item);
				})
				$("img[name=edit_img]").attr("src", data.logo.indexOf("http") == -1 ? (bucketUrl + data.logo) : (data.logo))
				//data.need_auth==0?$("#need_auth").removeClass("active").find('.fr_swich_txt').text('不需要'):$("#need_auth").addClass("active").find('.fr_swich_txt').text('需要')
			}

			function editNext() {
				$("#passwordModal").modal('show');
				$("#passwordModal input").val("");
			}
			function editSave() {
				
				// //logo
				// //chain_id
				// //name
				// //is_main
				// //is_default
				// //hot_max_coin
				// //agreement_address
				// //max_balance
				// //default_usd_price
				// //default_cny_price
				// //warn_balance
				// //hot_address
				// //hot_address_private_key
				// //cold_address
				
				// is_trc20
				// charge_coin_id
				// charge_number
				
				// //id
				// //op_password
				
				var list =['name','hot_max_coin','agreement_address','max_balance','id','warn_balance','hot_address','cold_address','default_cny_price','default_usd_price','charge_coin_id','charge_number','verify_num']
				var data = {
					chain_id: GetRequest().chain_id,
					is_main: $("#editCoinModal [name=is_main]:checked").val(),
					is_default: $("#editCoinModal [name=is_default]:checked").val(),
					op_password: $("#passwordModal [name=OPassword]").val(),
					is_trc20:$("#editCoinModal [name=is_trc20]").prop("checked")?1:0
					//need_auth:$("#need_auth").hasClass('active')?1:0
				}
				$.each(list,function(index,item){
					data[item] = $('#editCoinModal [name='+item+']').val();
				})
				
				console.log($("#editCoinModal img[name = edit_img]").attr("filerename"))
				
				
				if($("#editCoinModal [name = hot_address_private_key]").val() != $("#editCoinModal [name = hot_address_private_key]").attr("oldValue")){
					data.hot_address_private_key = $("#editCoinModal [name = hot_address_private_key]").val()
				}
				
				if($("#editCoinModal img[name = edit_img]").attr("filerename")) {
					data.logo = $("#editCoinModal img[name = edit_img]").attr("filerename")
				}
				$.ajax({
					type: "post",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					"contentType": "application/x-www-form-urlencoded",
					url: url + "Back_CoinUpdate",
					data: {
						data: JSON.stringify(data)
					},
					dataType: "json",
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#passwordModal").modal("hide");
						$("#editCoinModal").modal("hide");
						move("success", '修改成功');
						table.draw(false);
					}
				})
			}
			function add(){
				$("#addCoinModal").modal('show');
				$("#addCoinModal").find('input[type=text]').val('')
			}
			function addNext(){
				if($("#addCoinModal [name=name]").val() == ''){
					alert('请输入币种名称！')
					return false;
				}
				
				$("#addPasswordModal").modal('show');
				$("#addPasswordModal input").val("");
			}
			function addSave() {
				console.log($('#addCoinModal [name=charge_coin_id]').val())
				var list =['name','hot_max_coin','agreement_address','max_balance','warn_balance','hot_address','cold_address','default_cny_price','default_usd_price','charge_coin_id','charge_number']
				var data = {
					chain_id: GetRequest().chain_id,
					is_main: $("#addCoinModal [name=add_is_main]:checked").val(),
					is_default: $("#addCoinModal [name=add_is_default]:checked").val(),
					op_password: $("#addPasswordModal [name=OPassword]").val(),
					is_trc20:$("#addPasswordModal [name=is_trc20]").prop("checked")?1:0
				}
				$.each(list,function(index,item){
					data[item] = $('#addCoinModal [name='+item+']').val();
				})
				
				data.hot_address_private_key = $("#addCoinModal [name = hot_address_private_key]").val()
				
				if($("#addCoinModal img[name = edit_img]").attr("filerename")) {
					data.logo = $("#addCoinModal img[name = edit_img]").attr("filerename")
				}
				$.ajax({
					type: "post",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					"contentType": "application/x-www-form-urlencoded",
					url: url + "Back_CoinAdd",
					data: {
						data: JSON.stringify(data)
					},
					dataType: "json",
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#addPasswordModal").modal("hide");
						$("#addCoinModal").modal("hide");
						move("success", '修改成功');
						table.draw(false);
					}
				})
			}
			
			$(".onePic").change(function() {
				var date = new Date()
				var fileRename = date.valueOf()+Math.ceil(Math.random()*100);
				var file = $(this)[0].files[0];
				var that = $(this)
				var data = {
					file: file,
					fileRename: fileRename
				};
				var errorCallBack = function(res) {
					console.log(res)
				};
				var successCallBack = function(res) {
					console.log(res)
					console.log(that)
					that.siblings('img').attr("src", bucketUrl + fileRename).attr("fileRename", fileRename)
				};
				var progressCallBack = function(res) {};

				ufile.uploadFile(data, successCallBack, errorCallBack, progressCallBack);
			})
		</script>
	</body>

</html>